package vip.mall.modular.comment.controller;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import vip.mall.common.result.CommonResult;
import vip.mall.modular.comment.entity.Comment;
import vip.mall.modular.comment.params.CommentPageParams;
import vip.mall.modular.comment.service.CommentService;
/**
 * @author Asus
 * @Date 2025/2/10 11:43
 * @Descripition 评论模块控制器
 */
@RestController
@RequestMapping("/comment")
@Tag(name="评论模块控制器")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 添加评论
     */
    @PostMapping("/add")
    @Operation(summary = "添加评论")
    public CommonResult addComment(@RequestBody Comment comment) {
        if (ObjectUtil.isEmpty(comment)) {
            return CommonResult.error("评论不能为空");
        }
        boolean result = commentService.save(comment);
        return result ?CommonResult.success():CommonResult.error();
    }
    /**
     * 删除评论
     */
    @PostMapping("/delete")
    @Operation(summary = "删除评论")
    public CommonResult deleteComment(@RequestParam ("id") String id) {
        boolean result = commentService.removeById(id);
        return result ?CommonResult.success():CommonResult.error();
    }
    /**
     * 修改评论
     */
    @PostMapping("/edit")
    @Operation(summary="修改评论")
    public CommonResult editComment(@RequestBody Comment comment){
        boolean result=commentService.updateById(comment);
        return result?CommonResult.success():CommonResult.error();
    }
    /**
     * 获取评论列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取评论列表")
    public CommonResult listComment(){
        return CommonResult.success(commentService.list());
    }
    /**
     * 分页获取评论列表
     */
    @PostMapping("/page")
    @Operation(summary = "分页获取评论列表")
        public CommonResult pageComment(@RequestBody CommentPageParams commentPageParams){
            return CommonResult.success(commentService.pageList(commentPageParams));
    }
    }







